# Contributor: Nicolas Lorin <androw95220@gmail.com>
# Maintainer: psykose <alice@ayaya.dev>
pkgname=prometheus-wireguard-exporter
pkgver=3.6.3
pkgrel=0
pkgdesc="A Prometheus exporter for WireGuard, written in Rust"
url="https://github.com/MindFlavor/prometheus_wireguard_exporter"
# ppc64le: https://github.com/briansmith/ring/issues/389
# s390x, riscv64: cargo
arch="all !s390x !ppc64le !riscv64"
license="MIT"
makedepends="cargo"
subpackages="$pkgname-openrc"
source="https://github.com/MindFlavor/prometheus_wireguard_exporter/archive/$pkgver/prometheus_wireguard_exporter-$pkgver.tar.gz
	prometheus-wireguard-exporter.initd
	prometheus-wireguard-exporter.confd
	"
options="net"
builddir="$srcdir"/prometheus_wireguard_exporter-"$pkgver"

# optimize binary for size
export CARGO_PROFILE_RELEASE_LTO=true
export CARGO_PROFILE_RELEASE_PANIC=abort
export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1
export CARGO_PROFILE_RELEASE_OPT_LEVEL="s"

prepare() {
	default_prepare

	cargo fetch --locked
}

build() {
	cargo build --release --frozen
}

check() {
	cargo test --frozen
}

package() {
	install -Dm755 target/release/prometheus_wireguard_exporter \
		-t "$pkgdir"/usr/bin

	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="
e4b66aa92f1710a56d8d21317b7777c014b1399cdebda470007e6cc6508aa6fa8b0f81404e2c59128d18c1d73f988afad3b9e9b34266811d7fcb8dfedfa6bd16  prometheus_wireguard_exporter-3.6.3.tar.gz
649b119f8a91835e1d9af225359d9d1aec2b4ef501a59c93dd23fefffec194fe2417815003edbe5a3de1323392d4ae045b9af26d4664d72d729fc5c7c6c63279  prometheus-wireguard-exporter.initd
aaf53d1a2e3f8b672b05f73542b51fc52c0491eaba92b43da4fe43250ba880ca2a439b4faa0a9fbac58fbf8db8936780ec2dd48203c79ea80e87ce06655ac962  prometheus-wireguard-exporter.confd
"
